<?php

class missionDetail
{
	private $id;				//任务ID
	private $name;				//名称
	private $type;				//任务类型（1：长期，2：日常，3：特殊日期）
	private $loop;				//能否反复接	
	private $describe;			//任务界面中的描述
	
	private $startTime;		//在特殊日期类任务中从什么时间开始开启任务（例如：1301040600 是指2013年1月4日上午6点任务开始开启）
	private $valid;				//在特殊日期类任务中任务开启的时间，过时则任务自动关闭，已接到的此任务如没完成则变为过期（单位是小时）	
	
	private $tipsType;			// 1：在指挥部接的任务， 2：主动跳出界面的任务（比如新手引导），3：在对话过程中出现的任务
	private $tipsText;			//在任务出现或接任务时的文字内容，根据tipsType不同，文字出现的形式不同
	private $tipsPos;			//当tipsType类型为2时，提示信息的坐标
	/*
	{
		offsetX:Number		偏移坐标			
		offsetY:Number		偏移坐标
		
		ui:int				在哪个UI的坐标基础上偏移（设为0的话则是基于画布左上角）
	}*/
		
	private $acquireRequire;	//可接条件
	/*
	{
		level:int   		接受任务所需等级
			
		money:int			接受任务所需押金（任务开始时扣除，任务成功返还，任务失败则不会返还）
			
		item:Array 			接受任务所需道具
		(
			{itemID:int,inc:int,itemNum:int}
		)
	}*/
		
	private $completeRequire;	//完成条件
	/*
	{
		ui:int			完成任务所需点击的UI
			
		map:int			完成任务需要去的地图
			
		item:Array		完成任务所需取得的道具(inc是道具强化的等级)
		(
			{itemID:int,inc:int,itemNum:int}
		)
			
		enemy:Array		完成任务需打败的敌物
		(
			{enemyID:int,enemyNum:int}
		)
	}*/
		
	private $reward;			//奖励
	/*
	{
		money:int		完成任务奖励的资金
			
		exp:int			完成任务奖励的经验
			
		mission:Array		完成任务奖励的任务（type=1是奖励任务，type=-1是扣除任务）
		(
			{id:int,type:int}
		)
			
		item:Array		完成任务奖励的道具（itemNum为负数则是扣除道具）
		(
			{itemID:int,inc:int,itemNum:int}
		)
	}*/
		
	
	public function missionDetail($id)
	{
		$xml = simplexml_load_file("ini/missions/m_".$id.".xml"); 
		
		$this->id = (int)$xml['id'];
		$this->name = (string)$xml['name'];				
		$this->type = (int)$xml['type'];				
		$this->loop = (int)$xml['loop']=="true"?1:0;
		$this->tipsType = (int)$xml['tipsType'];			
		$this->tipsText = (string)$xml['tipsText'];
		$this->startTime = (int)$xml['startTime'];		
		$this->valid = (int)$xml['valid'];	
		$this->describe = (string)$xml->describe;			
		$this->tipsPos = array("offsetX"=>(int)$xml->tipsPos['offsetX'],"offsetY"=>(int)$xml->tipsPos['offsetY'],"ui"=>(int)$xml->tipsPos['ui']);
		
		//解析可接条件
		$this->acquireRequire = array(
			"level"=>(int)$xml->acquireRequire['level'],
			"money"=>(int)$xml->acquireRequire['money'],	
		);
	
		$ary = array();
		foreach($xml->acquireRequire->item as $data)
		{
			$ary[]=array(
					"id"=>(int)$data['id'],
					"inc"=>(int)$data['inc'],
					"num"=>(int)$data['num']
				);
		};
			
		$this->acquireRequire["item"] = $ary;
		
		//解析完成条件
		$this->completeRequire = array(
			"ui"=>(int)$xml->completeRequire['ui'],
			"map"=>(int)$xml->completeRequire['map'],
		);
		
		$ary = array();
		foreach($xml->completeRequire->item as $data)
		{
			$ary[]=array(
				"id"=>(int)$data['id'],
				"inc"=>(int)$data['inc'],
				"num"=>(int)$data['num']
				);
		};
		$this->completeRequire["item"] = $ary;
		
		$ary = array();
		foreach($xml->completeRequire->enemy as $data)
		{
			$ary[]=array(
				"id"=>(int)$data['id'],
				"num"=>(int)$data['num']
				);
		};
		$this->completeRequire["enemy"] = $ary;
		
		//解析奖励
		$this->reward = array(
			"money"=>(int)$xml->reward['money'],
			"exp"=>(int)$xml->reward['exp'],
		);
	
		$ary = array();
		foreach($xml->reward->item as $data)
		{
			$ary[]=array(
				"id"=>(int)$data['id'],
				"inc"=>(int)$data['inc'],
				"num"=>(int)$data['num']
				);
		};
		$this->reward["item"] = $ary;
	}
	
	/////////////////////////////////////////////
	public function __set($name, $value) 
	{
		if (! isset($this->$name))
		{       
			$this->$name = $value;
		}
	}
	
	public function __get($name)
	{
		if( isset( $this->$name ) ) 
		{    
			return $this->$name;
		} else {
			trigger_error( $name . ' variables undefined',  E_USER_NOTICE );
		}
	}
	
}

?>

